﻿using System;
using System.Windows.Forms;

namespace ThreadSafeControls {
    public class ThreadSafeColumnHeader {

        private readonly ColumnHeader _columnHeader;
        private readonly ThreadSafeListView _listView;

        internal ThreadSafeColumnHeader(ColumnHeader columnHeader, ThreadSafeListView listView) {
            if (columnHeader == null)
                throw new ArgumentNullException("columnHeader");
            else if (listView == null)
                throw new ArgumentNullException("listView");

            _columnHeader = columnHeader;
            _listView = listView;
        }

        internal ColumnHeader ColumnHeader {
            get { return _columnHeader; }
        }

        public int Index {
            get { return _listView.ReturnAsync(c => _columnHeader.Index); }
        }

        public ThreadSafeListView ListView {
            get { return _listView; }
        }

        public string Text {
            get { return _listView.ReturnAsync(c => _columnHeader.Text); }
            set { _listView.UpdateAsync(c => _columnHeader.Text = value); }
        }

        public HorizontalAlignment TextAlign {
            get { return _listView.ReturnAsync(c => _columnHeader.TextAlign); }
            set { _listView.UpdateAsync(c => _columnHeader.TextAlign = value); }
        }

        public int Width {
            get { return _listView.ReturnAsync(c => _columnHeader.Width); }
            set { _listView.UpdateAsync(c => _columnHeader.Width = value); }
        }

    }
}
